package com.warm.pump.module.skd.controller;

import com.warm.pump.frame.gen.bean.PageBean;
import com.warm.pump.frame.gen.util.MyBeanUtils;
import com.warm.pump.frame.gen.util.OutJson;
import com.warm.pump.frame.util.StringUtils;
import com.warm.pump.module.skd.bean.po.gen.ScheduleLog;
import com.warm.pump.module.skd.service.IScheduleLogService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.Map;

/**
 * skd_log
 */
@Controller
@RequestMapping("/scheduleLog")
public class ScheduleLogController {
    @Autowired
    private IScheduleLogService scheduleLogService;

    /**
     * 列表
     */
    @ResponseBody
    @RequestMapping("/list")
    @RequiresPermissions("scheduleLog:list")
    public OutJson list(Integer page, Integer limit, ScheduleLog scheduleLog) {
        Map<String, Object> map = new HashMap<>();
        MyBeanUtils.copyBean2Map(map, scheduleLog);
        if (null != scheduleLog.getCond() && scheduleLog.getCond().size() > 0) {
            map.putAll(scheduleLog.getCond());
        }

        map.put("orderBy", "start_time desc");
        if (StringUtils.isNotEmpty(scheduleLog.getSidx()) && StringUtils.isNotEmpty(scheduleLog.getOrder())) {
            map.put("orderBy", scheduleLog.getSidx() + " " + scheduleLog.getOrder());
        }
        //查询列表数据
        PageBean pageBean = scheduleLogService.getPageBeanByMap(map, page, limit);

        return OutJson.ok().put("page", pageBean);
    }


    /**
     * 信息
     */
    @ResponseBody
    @RequestMapping("/info/{id}")
    @RequiresPermissions("scheduleLog:info")
    public OutJson info(@PathVariable("id") Long id) {
        ScheduleLog scheduleLog = scheduleLogService.queryObject(id);

        return OutJson.ok().put("scheduleLog", scheduleLog);
    }


    /**
     * 保存
     */
    @ResponseBody
    @RequestMapping("/save")
    @RequiresPermissions("scheduleLog:save")
    public OutJson save(@RequestBody ScheduleLog scheduleLog) {
        scheduleLogService.save(scheduleLog);

        return OutJson.ok();
    }

    /**
     * 修改
     */
    @ResponseBody
    @RequestMapping("/update")
    @RequiresPermissions("scheduleLog:update")
    public OutJson update(@RequestBody ScheduleLog scheduleLog) {
        scheduleLogService.update(scheduleLog);

        return OutJson.ok();
    }

    /**
     * 删除
     */
    @ResponseBody
    @RequestMapping("/delete")
    @RequiresPermissions("scheduleLog:delete")
    public OutJson delete(@RequestBody Long[] ids) {
        scheduleLogService.deleteBatch(ids);

        return OutJson.ok();
    }

}
